/**
 * @author 雷明浩
 * @date 2025/6/3 15:27
 */
public class OddEvenList {
    // newcoder 链表的奇偶排序
    // https://www.nowcoder.com/practice/02bf49ea45cd486daa031614f9bd6fc3?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
    public ListNode oddEvenList (ListNode head) {
        // write code here
        ListNode phead1 = new ListNode(-1);
        ListNode phead2 = new ListNode(-1);
        ListNode cur1 = phead1;
        ListNode cur2 = phead2;
        ListNode cur = head;
        for (int i = 1; cur != null; i++) {
            if (i % 2 == 1) {
                cur1.next = cur;
                cur1 = cur1.next;
            }else {
                cur2.next = cur;
                cur2 = cur2.next;
            }
            cur = cur.next;
        }
        cur1.next = phead2.next;
        cur2.next = null;
        return phead1.next;
    }
}